class Solution {
    public String countAndSay(int n) {
        String ret ="1";
        for (int i = 1; i < n; i++) {//循环N-1次 (N == 1，不用循环；N == 2，循环1次；.....)
            int left = 0;
            int right = 0;
            StringBuilder stringBuilder = new StringBuilder();
            int len = ret.length();
            while (right < len) {
                while (right < len && ret.charAt(left) == ret.charAt(right)) right++;
                stringBuilder.append(right - left);
                stringBuilder.append(ret.charAt(left));
                left = right;
            }
            ret = stringBuilder.toString();
        }
        return ret;
    }
}